home *** CD-ROM | disk | FTP | other *** search
/ Aminet 41 / Aminet 41 (2001)(Schatztruhe)[!][Feb 2001].iso / Tools / ClassAct / Examples / ListBrowser / LB_Example.c < prev    next >
C/C++ Source or Header  |  1997-04-27  |  10KB  |  383 lines

  1. #include <exec/types.h>
  2. #include <exec/memory.h>
  3. #include <dos/dos.h>
  4. #include <graphics/gfxmacros.h>
  5. #include <intuition/intuition.h>
  6. #include <intuition/gadgetclass.h>
  7. #include <intuition/imageclass.h>
  8. #include <intuition/icclass.h>
  9. #include <gadgets/listbrowser.h>
  10. #include <images/label.h>
  11. #include <libraries/asl.h>
  12. #include <libraries/gadtools.h>
  13. #include <utility/tagitem.h>
  14. #include <proto/asl.h>
  15. #include <proto/dos.h>
  16. #include <proto/diskfont.h>
  17. #include <proto/exec.h>
  18. #include <proto/gadtools.h>
  19. #include <proto/graphics.h>
  20. #include <proto/icon.h>
  21. #include <proto/intuition.h>
  22. #include <proto/utility.h>
  23. #include <proto/wb.h>
  24. #include <classact.h>
  25. #include <stdio.h>
  26. #include <string.h>
  27.  
  28.  
  29. ULONG __asm __saveds lb_hook(register __a0 struct Hook *hook, register
  30.                         __a2 struct Node *node, register __a1 struct LBDrawMsg *msg);
  31.  
  32. struct ColumnInfo ci[] =
  33. {
  34.     { 100, "Column Header", 0 },
  35.     { -1, (STRPTR)~0, -1 }
  36. };
  37.  
  38. struct TextAttr emerald17 = { (STRPTR)"emerald.font", 18, FS_NORMAL, 0x01 };
  39.  
  40.  
  41. /* Here's where it all starts.
  42.  */
  43. main()
  44. {
  45.     struct Screen *screen = NULL;
  46.  
  47.     if (!ButtonBase) return(20);
  48.  
  49.     /* We'll just open up on the default public screen, and use its screen font.
  50.      */
  51.     if (screen = LockPubScreen(NULL))
  52.     {
  53.     struct TextAttr emerald17 = { (STRPTR)"emerald.font", 18, FS_NORMAL, 0x01 };
  54.         struct DrawInfo *drinfo = GetScreenDrawInfo(screen);
  55.         Object *layout;
  56.         struct Gadget *lb_gad;
  57.         struct List list;
  58.         struct Image *limage, *gimage;
  59.         struct Hook lbhook;
  60.  
  61.         NewList(&list);
  62.  
  63.         if (layout = LayoutObject,
  64.                         GA_DrawInfo, drinfo,
  65.                         LAYOUT_DeferLayout, TRUE,    /* Layout refreshes done on
  66.                                                      * task's context (by the
  67.                                                      * window class) */
  68.                         LAYOUT_SpaceOuter, TRUE,
  69.                         LAYOUT_AddChild, lb_gad = ListBrowserObject,
  70.                             GA_ID, 1,
  71.                             GA_RelVerify, TRUE,
  72.                             LISTBROWSER_Labels, &list,
  73.                             LISTBROWSER_ColumnInfo, &ci,
  74.                             LISTBROWSER_ColumnTitles, TRUE,
  75.                             LISTBROWSER_Separators, TRUE,
  76.                             LISTBROWSER_Hierarchical, TRUE,
  77.                             LISTBROWSER_Editable, TRUE,
  78.                             LISTBROWSER_MultiSelect, TRUE,
  79.                             LISTBROWSER_ShowSelected, TRUE,
  80.                             ListBrowserEnd,
  81.  
  82.                         LayoutEnd)
  83.         {
  84.             struct MsgPort *app_port;
  85.             Object *window_obj;
  86.  
  87.             LBAddNode(lb_gad, NULL, NULL, (struct Node *)~0,
  88.                 LBNA_Generation, 1,
  89.                 LBNA_Column, 0,
  90.                     LBNCA_CopyText, TRUE,
  91.                     LBNCA_Text, "Demo of ListBrowserNode features",
  92.                 TAG_DONE);
  93.  
  94.             LBAddNode(lb_gad, NULL, NULL, (struct Node *)~0,
  95.                 LBNA_Generation, 1,
  96.                 LBNA_Flags, LBFLG_HASCHILDREN | LBFLG_SHOWCHILDREN,
  97.                 LBNA_Column, 0,
  98.                     LBNCA_CopyText, TRUE,
  99.                     LBNCA_Text, "Editable node",
  100.                 TAG_DONE);
  101.  
  102.             LBAddNode(lb_gad, NULL, NULL, (struct Node *)~0,
  103.                 LBNA_Generation, 2,
  104.                 LBNA_Column, 0,
  105.                     LBNCA_CopyText, TRUE,
  106.                     LBNCA_Text, "Click twice to edit",
  107.                     LBNCA_Editable, TRUE,
  108.                     LBNCA_MaxChars, 60,
  109.                 TAG_DONE);
  110.  
  111.             LBAddNode(lb_gad, NULL, NULL, (struct Node *)~0,
  112.                 LBNA_Generation, 1,
  113.                 LBNA_Flags, LBFLG_HASCHILDREN | LBFLG_SHOWCHILDREN,
  114.                 LBNA_Column, 0,
  115.                     LBNCA_CopyText, TRUE,
  116.                     LBNCA_Text, "Change colours",
  117.                 TAG_DONE);
  118.  
  119.             LBAddNode(lb_gad, NULL, NULL, (struct Node *)~0,
  120.                 LBNA_Generation, 2,
  121.                 LBNA_Flags, LBFLG_CUSTOMPENS,
  122.                 LBNA_Column, 0,
  123.                     LBNCA_CopyText, TRUE,
  124.                     LBNCA_Text, "Colourful!",
  125.                     LBNCA_FGPen, 19,
  126.                     LBNCA_BGPen, 18,
  127.                 TAG_DONE);
  128.  
  129.             LBAddNode(lb_gad, NULL, NULL, (struct Node *)~0,
  130.                 LBNA_Generation, 1,
  131.                 LBNA_Flags, LBFLG_HASCHILDREN | LBFLG_SHOWCHILDREN,
  132.                 LBNA_Column, 0,
  133.                     LBNCA_CopyText, TRUE,
  134.                     LBNCA_Text, "Checkbox item",
  135.                 TAG_DONE);
  136.  
  137.             LBAddNode(lb_gad, NULL, NULL, (struct Node *)~0,
  138.                 LBNA_Generation, 2,
  139.                 LBNA_CheckBox, TRUE,
  140.                 LBNA_Checked, TRUE,
  141.                 LBNA_Column, 0,
  142.                     LBNCA_CopyText, TRUE,
  143.                     LBNCA_Text, "Checked by default",
  144.                 TAG_DONE);
  145.  
  146.             LBAddNode(lb_gad, NULL, NULL, (struct Node *)~0,
  147.                 LBNA_Generation, 2,
  148.                 LBNA_CheckBox, TRUE,
  149.                 LBNA_Checked, FALSE,
  150.                 LBNA_Column, 0,
  151.                     LBNCA_CopyText, TRUE,
  152.                     LBNCA_Text, "Unchecked by default",
  153.                 TAG_DONE);
  154.  
  155.             LBAddNode(lb_gad, NULL, NULL, (struct Node *)~0,
  156.                 LBNA_Generation, 1,
  157.                 LBNA_Flags, LBFLG_HASCHILDREN | LBFLG_SHOWCHILDREN,
  158.                 LBNA_Column, 0,
  159.                     LBNCA_CopyText, TRUE,
  160.                     LBNCA_Text, "Justifications",
  161.                 TAG_DONE);
  162.  
  163.             LBAddNode(lb_gad, NULL, NULL, (struct Node *)~0,
  164.                 LBNA_Generation, 2,
  165.                 LBNA_Column, 0,
  166.                     LBNCA_CopyText, TRUE,
  167.                     LBNCA_Text, "Left",
  168.                     LBNCA_Justification, LCJ_LEFT,
  169.                 TAG_DONE);
  170.  
  171.             LBAddNode(lb_gad, NULL, NULL, (struct Node *)~0,
  172.                 LBNA_Generation, 2,
  173.                 LBNA_Column, 0,
  174.                     LBNCA_CopyText, TRUE,
  175.                     LBNCA_Text, "Centre",
  176.                     LBNCA_Justification, LCJ_CENTRE,
  177.                 TAG_DONE);
  178.  
  179.             LBAddNode(lb_gad, NULL, NULL, (struct Node *)~0,
  180.                 LBNA_Generation, 2,
  181.                 LBNA_Column, 0,
  182.                     LBNCA_CopyText, TRUE,
  183.                     LBNCA_Text, "Right",
  184.                     LBNCA_Justification, LCJ_RIGHT,
  185.                 TAG_DONE);
  186.  
  187.             LBAddNode(lb_gad, NULL, NULL, (struct Node *)~0,
  188.                 LBNA_Generation, 1,
  189.                 LBNA_Flags, LBFLG_HASCHILDREN | LBFLG_SHOWCHILDREN,
  190.                 LBNA_Column, 0,
  191.                     LBNCA_CopyText, TRUE,
  192.                     LBNCA_Text, "Read-Only node",
  193.                 TAG_DONE);
  194.  
  195.             LBAddNode(lb_gad, NULL, NULL, (struct Node *)~0,
  196.                 LBNA_Generation, 2,
  197.                 LBNA_Flags, LBFLG_READONLY,
  198.                 LBNA_Column, 0,
  199.                     LBNCA_CopyText, TRUE,
  200.                     LBNCA_Text, "Can't select me!",
  201.                 TAG_DONE);
  202.  
  203.             gimage = GlyphObject,
  204.                         IA_Width, 20,
  205.                         IA_Height, 20,
  206.                         GLYPH_Glyph, GLYPH_POPTIME,
  207.                         GlyphEnd;
  208.             limage = LabelObject,
  209.                         IA_Font, &emerald17,
  210.                         LABEL_Text, "Created using _label.image\n",
  211.                         IA_Font, screen->Font,
  212.                         LABEL_SoftStyle, FSF_BOLD | FSF_ITALIC,
  213.                         LABEL_Image, gimage,
  214.                         IA_FGPen, 35,
  215.                         LABEL_Text, " Cool eh?",
  216.                         LabelEnd;
  217.  
  218.             LBAddNode(lb_gad, NULL, NULL, (struct Node *)~0,
  219.                 LBNA_Generation, 1,
  220.                 LBNA_Flags, LBFLG_HASCHILDREN | LBFLG_SHOWCHILDREN,
  221.                 LBNA_Column, 0,
  222.                     LBNCA_CopyText, TRUE,
  223.                     LBNCA_Text, "Some images",
  224.                 TAG_DONE);
  225.  
  226.             LBAddNode(lb_gad, NULL, NULL, (struct Node *)~0,
  227.                 LBNA_Generation, 2,
  228.                 LBNA_Column, 0,
  229.                     LBNCA_Image, limage,
  230.                 TAG_DONE);
  231.  
  232.             lbhook.h_Entry = (ULONG (*)())lb_hook;
  233.             lbhook.h_SubEntry = NULL;
  234.             lbhook.h_Data = NULL;
  235.  
  236.             LBAddNode(lb_gad, NULL, NULL, (struct Node *)~0,
  237.                 LBNA_Generation, 1,
  238.                 LBNA_Flags, LBFLG_HASCHILDREN | LBFLG_SHOWCHILDREN,
  239.                 LBNA_Column, 0,
  240.                     LBNCA_CopyText, TRUE,
  241.                     LBNCA_Text, "Rendering hook",
  242.                 TAG_DONE);
  243.  
  244.             LBAddNode(lb_gad, NULL, NULL, (struct Node *)~0,
  245.                 LBNA_Generation, 2,
  246.                 LBNA_Column, 0,
  247.                     LBNCA_RenderHook, &lbhook,
  248.                     LBNCA_HookHeight, 20,
  249.                 TAG_DONE);
  250.  
  251.             /* Create a message port for App* messages.  This is needed for
  252.              * iconification.  We're being a touch naughty by not checking
  253.              * the return code, but that just means that iconification won't
  254.              * work, nothing really bad will happen.
  255.              */
  256.             app_port = CreateMsgPort();
  257.  
  258.             /* Create the window object.
  259.              */
  260.             if (window_obj = WindowObject,
  261.                                 WA_Left, 0,
  262.                                 WA_Top, screen->Font->ta_YSize + 3,
  263.                                 WA_CustomScreen, screen,
  264.                                 WA_IDCMP, IDCMP_CLOSEWINDOW | IDCMP_REFRESHWINDOW,
  265.                                 WA_Flags, WFLG_DRAGBAR | WFLG_DEPTHGADGET | WFLG_CLOSEGADGET |
  266.                                             WFLG_SIZEGADGET | WFLG_ACTIVATE | WFLG_SMART_REFRESH,
  267.                                 WA_Title, "ListBrowser class example",
  268.                                 WA_InnerWidth, 300,
  269.                                 WA_InnerHeight, 200,
  270.                                 WA_NewLookMenus, TRUE,
  271.                                 WINDOW_ParentGroup, layout,
  272.                                 WINDOW_IconifyGadget, TRUE,
  273.                                 WINDOW_Icon, GetDiskObject("PROGDIR:LB_Example"),
  274.                                 WINDOW_IconTitle, "LB_Example",
  275.                                 WINDOW_AppPort, app_port,
  276.                                 TAG_DONE))
  277.             {
  278.                 struct Window *win;
  279.  
  280.                 /*  Open the window.
  281.                  */
  282.                 if (win = (struct Window *)CA_OpenWindow(window_obj))
  283.                 {
  284.                     ULONG signal;
  285.                     BOOL ok = TRUE;
  286.  
  287.                     /* Obtain the window wait signal mask.
  288.                      */
  289.                     GetAttr(WINDOW_SigMask, window_obj, &signal);
  290.  
  291.                     /* Input Event Loop
  292.                      */
  293.                     while (ok)
  294.                     {
  295.                         ULONG result;
  296.  
  297.                         Wait(signal | (1L << app_port->mp_SigBit));
  298.  
  299.                         /* CA_HandleInput() returns the gadget ID of a clicked
  300.                          * gadget, or one of several pre-defined values.  For
  301.                          * this demo, we're only actually interested in a
  302.                          * close window and a couple of gadget clicks.
  303.                          */
  304.                         while ((result = CA_HandleInput(window_obj, NULL)) != WMHI_LASTMSG)
  305.                         {
  306.                             switch(result & WMHI_CLASSMASK)
  307.                             {
  308.                                 case WMHI_CLOSEWINDOW:
  309.                                     ok = FALSE;
  310.                                     break;
  311.  
  312.                                 case WMHI_GADGETUP:
  313.                                     switch (result & WMHI_GADGETMASK)
  314.                                     {
  315.                                         default:
  316.                                             break;
  317.                                     }
  318.                                     break;
  319.  
  320.                                 case WMHI_ICONIFY:
  321.                                     if (CA_Iconify(window_obj))
  322.                                         win = NULL;
  323.                                     break;
  324.                              
  325.                                 case WMHI_UNICONIFY:
  326.                                     win = CA_OpenWindow(window_obj);
  327.                                     break;
  328.  
  329.                                 default:
  330.                                     break;
  331.                             }
  332.                         }
  333.                     }
  334.                  }
  335.                 else
  336.                     PutStr("ERROR: failed to start.  Couldn't open window\n");
  337.  
  338.                 /* Disposing of the window object will also close the
  339.                  * window if it is already opened and it will dispose of
  340.                  * all objects attached to it.
  341.                  */
  342.                 DisposeObject(window_obj);
  343.             }
  344.             else
  345.                 PutStr("ERROR: failed to start.  Couldn't create window\n");
  346.  
  347.             /* Lose the App* message port.
  348.              */
  349.             if (app_port)
  350.                 DeleteMsgPort(app_port);
  351.         }
  352.         else
  353.             PutStr("ERROR: failed to start.  Couldn't create layout\n");
  354.  
  355.         if (drinfo)
  356.             FreeScreenDrawInfo(screen, drinfo);
  357.  
  358.         UnlockPubScreen(0, screen);
  359.     }
  360.     else
  361.         PutStr("ERROR: failed to start.  Couldn't lock destination screen\n");
  362.  
  363.     exit(0);
  364. }
  365.  
  366. ULONG __asm __saveds lb_hook(register __a0 struct Hook *hook, register
  367.                         __a2 struct Node *node, register __a1 struct LBDrawMsg *msg)
  368. {
  369.     UWORD patterndata[2] = { 0x2222, 0x8888 };
  370.     WORD width = msg->lbdm_Bounds.MaxX - msg->lbdm_Bounds.MinX;
  371.     WORD height = msg->lbdm_Bounds.MaxY - msg->lbdm_Bounds.MinY;
  372.  
  373.     if(msg->lbdm_MethodID != LV_DRAW)
  374.         return(LBCB_UNKNOWN);
  375.  
  376.     SetAPen(msg->lbdm_RastPort, 69);
  377.     DrawEllipse(msg->lbdm_RastPort,
  378.         msg->lbdm_Bounds.MinX + (width / 2), msg->lbdm_Bounds.MinY + (height / 2),
  379.         width / 2, height / 2);
  380.         
  381.     return(LVCB_OK);
  382. }
  383.